package com.congee02.sw.reach.init;

import java.util.Comparator;
import java.util.PriorityQueue;

public class GetStrongest {

    public int[] getStrongest(int[] nums, int k) {

        int median = median(nums);

        int[] ans = new int[k];

        PriorityQueue<Integer> heap = new PriorityQueue<>((o1, o2) -> {

            int a1 = Math.abs(o1 - median);
            int a2 = Math.abs(o2 - median);

            if (a1 != a2) {
                return a2 - a1;
            }

            return o2 - o1;
        });

        for (int x : nums) {
            heap.offer(x);
        }

        for (int i = 0 ; i < k ; i ++ ) {
            ans[i] = heap.poll();
        }

        return nums;
    }

}
